We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Render a Controller -> action -> view from .volt or .html

Hi,

I have a view which prints the latest posts of my blog, controller -> action latestPostsAction(); this action takes from database te listo of the recent 10 posts. and uses its view.

the problem is that I want to render this view but with FULL process in diferent layouts, this means I have my index which shows in tle right this controller of a list of recent posts, but i want it also on the layout where the user read the posts.

In symfony they have:

<!-- app/Resources/views/base.html.php -->

<!-- ... --> <div id="sidebar"> <?php echo $view['actions']->render( new \Symfony\Component\HttpKernel\Controller\ControllerReference( 'AcmeArticleBundle:Article:recentArticles', array('max' => 3) ) ) ?> </div>

which does what I want, every time this module is called it asks for the list to the database . how do I do same behaviour on Phalcon?

Hi, try to read this part of documentation https://docs.phalcon.io/en/latest/reference/volt.html

And one notice: Its possible render .volt into string variable. Read this https://phalcon.agent-j.ru/en/1.3.0/Phalcon/Mvc/View#getRender-details



1.1k

Hi Peter, thanks for your response,

I already read that documentation and cant find what I need, the most similar thing is the partials and the getRender you mention,

but none of them go through the controller to render the view.

a clear example of what I need is

I have a controller with:

public function hiAction() { $this->view->setVar("name", "oplaza");

}

and its view

hi.volt

hi {{name}}, how are you

This can be done with a partial , sending the name as a parameter,

but what I want is to call to its controller which already have the param set.